package com.lmind.core;

import java.util.UUID;

public class UniqueID {
	
	private UUID uuid;
	
	private long timestamp;

	@Override
	public String toString() {
		return uuid.toString().replace("-", "") + toFixHex(timestamp, 16);
	}
	
	public static UniqueID create() {
		UniqueID uid = new UniqueID();
		uid.timestamp = System.currentTimeMillis();
		uid.uuid = UUID.randomUUID();
		return uid;
	}
	
	private static String toFixHex(long v, int len) {
		String hex = Long.toHexString(v);
		for (int i = hex.length(); i < len; i++) {
			hex = "0" + hex;
		}
		return hex;
	}
}
